<script setup lang="ts">
import * as echarts from 'echarts'
import { ref, onMounted } from 'vue'

//获取图形图标的DOM节点
let charts = ref()
onMounted(() => {
  let mycharts = echarts.init(charts.value)
  //设置配置项
  mycharts.setOption({
    //组件标题
    title: {
      text: '男女比例', //主标题
      textStyle: {
        //主标题颜色
        color: '#fff',
      },
    },
    tooltip: {
      trigger: 'axis',
    },
    //x|y
    xAxis: {
      show: false,
      min: 0,
      max: 100,
    },
    yAxis: {
      show: false,
      type: 'category',
    },
    series: [
      {
        name: '男女比例',
        type: 'bar',
        data: [58],
        barWidth: 20,
        z: 100,
        itemStyle: {
          color: '#007afe',
          borderRadius: 20,
        },
      },
      {
        type: 'bar',
        data: [100],
        barWidth: 20,
        //调整女士柱条位置
        barGap: '-100%',
        itemStyle: {
          color: '#ff4b7a',
          borderRadius: 20,
        },
      },
    ],
    grid: {
      left: 0,
      top: 0,
      right: 0,
      bottom: 0,
    },
  })
})
</script>

<template>
  <div class="sex">
    <div class="title">
      <p>男女比例</p>
      <div class="img"></div>
    </div>
    <div class="scaleDrawing">
      <div class="top">
        <div class="man">
          <p>男士</p>
          <img src="../images/man.png" alt="man" />
        </div>
        <div class="woman">
          <p>女士</p>
          <img src="../images/woman.png" alt="woman" />
        </div>
      </div>
      <div class="bottom" ref="charts"></div>
    </div>
  </div>
</template>

<style scoped lang="scss">
.sex {
  height: 340px;
  background: url('../images/dataScreen-main-lt.png') no-repeat;
  background-size: cover;
  color: white;
  position: relative;
  .title {
    font-size: 24px;
  }
  .img {
    width: 68px;
    height: 7px;
    background: url('../images/dataScreen-title.png') no-repeat;
    background-size: cover;
    margin-top: 8px;
  }
  .scaleDrawing {
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    align-items: center;
    width: 100%;
    height: 80%;
    .top {
      width: 70%;
      display: flex;
      justify-content: space-between;
      margin-top: 30px;
      .man,
      .woman {
        width: 111px;
        height: 116px;
        background: url('../images/man-bg.png') no-repeat;
        background-size: cover;
        position: relative;
        p {
          position: absolute;
          left: 50%;
          transform: translateX(-50%);
        }
        img {
          position: absolute;
          top: 60%;
          left: 50%;
          transform: translate(-50%, -50%);
        }
      }
      .woman {
        background: url('../images/woman-bg.png') no-repeat;
        background-size: cover;
      }
    }
    .bottom {
      width: 70%;
      height: 80px;
    }
  }
}
</style>
